package com.itcast.donkey.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.itcast.donkey.R;
import com.itcast.donkey.adapters.InAttackItemAdapter;
import com.itcast.donkey.adapters.ViewInAttackAdapter;
import com.itcast.donkey.modles.ScenicAttackModles;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/8/26.
 */
public class InAttackActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageView backScenicApot;
    private ImageView ivChanScenicSpot;
    private TextView tvTitleScenicSpot;
    private ImageView ivShareJourney;
    private ViewPager vpInAttack;
    private ScenicAttackModles modles;
    private ViewInAttackAdapter adapter;
    private InAttackItemAdapter itemAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_in_attack);
        initView();
        initData();
        initEvent();
    }


    private void initView() {

        backScenicApot = (ImageView) findViewById(R.id.back_scenic_apot);
        ivChanScenicSpot = (ImageView) findViewById(R.id.iv_chan_scenic_spot);
        tvTitleScenicSpot = (TextView) findViewById(R.id.tv_title_scenic_spot);
        ivShareJourney = (ImageView) findViewById(R.id.iv_share_journey);
        vpInAttack = (ViewPager) findViewById(R.id.vp_in_attack);
        
    }

    private void initData() {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        modles = (ScenicAttackModles) bundle.getSerializable("modlesArrayList");
        tvTitleScenicSpot.setText(modles.getPages().get(0).getTitle());


        List<RecyclerView> list = new ArrayList<>();

        for (int i = 0; i < modles.getPages().size(); i++) {
            List<ScenicAttackModles.PagesBean.ChildrenBean> clist = modles.getPages().get(i).getChildren();
            //多少个RecyclerView
            RecyclerView recyclerView = new RecyclerView(this);
            //adapter
            itemAdapter = new InAttackItemAdapter(InAttackActivity.this, clist);
            recyclerView.setAdapter(itemAdapter);
            //LayoutManager
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
            linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(linearLayoutManager);
            list.add(recyclerView);
        }
        adapter = new ViewInAttackAdapter(InAttackActivity.this, list);
        vpInAttack.setAdapter(adapter);
    }

    private void initEvent() {
        backScenicApot.setOnClickListener(this);
        ivChanScenicSpot.setOnClickListener(this);
        ivShareJourney.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_scenic_apot:
            case R.id.iv_chan_scenic_spot:
                finish();
                break;
            case R.id.iv_share_journey:
                break;
        }
    }
}
